<HTML>
<HEAD>

<TITLE>SQLite3LoggerPlugin</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</HEAD>
<link href="RaknetManual.css" rel="stylesheet" type="text/css">
<meta name="title" content="RakNet - Advanced multiplayer game networking API">
</HEAD>
<BODY BGCOLOR="#ffffff" LINK="#003399" vlink="#003399" alink="#003399" LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0"">
<span style="background-color: rgb(255, 255, 255);"><img src="RakNet_Icon_Final-copy.jpg" alt="Oculus VR, Inc." width="150" height="150"></span><BR>
<BR>

<table width="100%" border="0"><tr>
  <td bgcolor="#2c5d92" class="RakNetWhiteHeader">
<img src="spacer.gif" width="8" height="1">SQLite3LoggerPlugin Setup</td>
</tr></table>
<TABLE BORDER="0" CELLPADDING="10" CELLSPACING="0" WIDTH="100%"><TR>
  <TD>
    <p class="RakNetBlueHeader">Overview</p>
<p>RakNet's SQLLite3 logging system allows any system that supports TCP to send logs to a remote server. Logs automatically include the source file and line, as well as the time the log was sent, and the IP address of the sender. The logging system supports real-time DXT1 compression of screenshots, allowing for video replay of game sessions. SQL knowledge is not required to write logs, in fact logging is just as easy through RakNet as traditionally sent through printf. Variable types are automatically determined at compile time.</p>
    <p>Especially valuable is the ability to log multiplayer game sessions into a single log file. This allows the developer to view multiplayer sessions across a LAN, all on a single PC after the fact. Combined with automatic packet logging and network statistics, this allows analysis of multiplayer sessions with a high degree of precision.</p>
<p><span class="RakNetBlueHeader">SQLiteServerLoggerPlugin</span></p>
    <p>SQLiteServerLoggerPlugin derives from <a href="sqlite3plugin.html">SQLiteLogger</a>, adding the capability to write log files sent from SQLiteClientLogger.To start, simply run the project found at DependentExtensions\SQLite3Plugin\ServerOnly\SQLiteServerLoggerSample.cpp . In the Visual Studio 2005 solution, this is found under Samples / SQLite3Plugin / SQLiteServerLogger</p>
    <p>New SQL log files can be manually specified, or created automatically. To manually specify log files, create and register them the same way you do with <a href="sqlite3plugin.html">SQLiteLogger</a>. For example, this creates an in-memory database</p>
    <p class="RakNetCode">if (sqlite3_open_v2(&quot;:memory:&quot;, &amp;database, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0)!=SQLITE_OK)<br>
return 1;</p>
    <p class="RakNetCode"> static const char* DATABASE_IDENTIFIER=&quot;ConnectionStateDBInMemory&quot;;<br>
      sqlite3ServerPlugin.AddDBHandle(DATABASE_IDENTIFIER, database);</p>
<p>To automatically create log files based on new client sessions, use SQLiteServerLoggerPlugin::SetSessionManagementMode with either CREATE_EACH_NAMED_DB_HANDLE or CREATE_SHARED_NAMED_DB_HANDLE. CREATE_EACH_NAMED_DB_HANDLE will create one log file for each new connection that sends a log. CREATE_SHARED_NAMED_DB_HANDLE will create a new log file under the working directory every time a new connection sends a log, and closes that file when all connections have been lost. See SQLiteServerLoggerPlugin.h for more details on these settings.</p>
<p><strong>Minimal server setup using TCP:</strong></p>
<p class="RakNetCode">PacketizedTCP packetizedTCP;<br>
RakNet::SQLiteServerLoggerPlugin loggerPlugin;<br>
loggerPlugin.SetSessionManagementMode(RakNet::SQLiteServerLoggerPlugin::CREATE_SHARED_NAMED_DB_HANDLE, true, &quot;&quot;);<br>
packetizedTCP.AttachPlugin(&amp;loggerPlugin);<br>
packetizedTCP.Start(38123,8);</p>
<p>When raw image data is sent to the server, the server will compress it automatically if specified by the client (more on this in the client section below). The server can enable hardware based DXT compression if the number or size of images sent is too frequent for the CPU to keep up. Enable this setting with SQLiteServerLoggerPlugin::SetEnableDXTCompression(true). It requires that the server have a hardware accelerated 3D card. If the setting fails, the server will automatically use JPEG compression isntead. JPEG compression produces smaller files, so is the better choice if the CPU can keep up.</p>
<p><span class="RakNetBlueHeader">SQLiteClientLoggerPlugin</span></p>
<p>The client sources integrates with your application. You should add all files under DependentExtensions\SQLite3Plugin\ClientOnly to your application, except possibly SQLiteClientLogger_PacketLogger.h/.cpp and SQLiteClientLogger_RNSLogger.h/cpp as these are optional. They are <a href="plugininterface.html">plugins</a> used to log all packet logs, and RakNetStatistics respectively. You also have to add DependentExtensions\SQLite3Plugin\SQLiteLoggerCommon.h/.cpp</p>
<p>If your application does not already use RakNet, you will need to add RakNet source files under /Source as well. See the section on <a href="compilersetup.html">compiler setup</a> if needed.</p>
<p>There is also a <A HREF="http://www.jenkinssoftware.com/raknet/manual/SQLite3LoggerPluginVideo.html">video covering this plugin</A>.</p>
<p><strong>Minimal client setup using TCP:</strong></p>
<p class="RakNetCode">PacketizedTCP packetizedTCP;<br>
RakNet::SQLiteClientLoggerPlugin loggerPlugin;<br>
packetizedTCP.AttachPlugin(&amp;loggerPlugin);<br>
packetizedTCP.Start(0,0);<br>
SystemAddress serverAddress = packetizedTCP.Connect(&quot;127.0.0.1&quot;, 38123, true);<br>
// Assuming connection completed. See TCPInterface::HasNewIncomingConnection()<br>
loggerPlugin.SetServerParameters(serverAddress, &quot;functionLog.sqlite&quot;);</p>
<p>In this case, we are assuming the server is located at localhost (127.0.0.1) on port 38123. The port is arbitrary, and is whatever you used on the server.</p>
<p>&quot;functionLog.sqlite&quot; is the name of the first parameter passed to <span class="RakNetCode">SQLite3ServerPlugin::AddDBHandle</span>. However, if you are using CREATE_SHARED_NAMED_DB_HANDLE or CREATE_EACH_NAMED_DB_HANDLE on the server, then this file will be created instead. It is OK for the application to use the same name, as the files are stored in separate directories. In fact, for multiplayer, you want all systems to use the same name so all logs are put into the same file and can be compared time-relative to each other.</p>
<p>To constrain the amount of memory used by the system, use SQLiteClientLoggerPlugin::SetMemoryConstraint(unsigned int constraint). This is important if sending a lot of data. Otherwise if the server crashes, the application may consume a lot of memory until the crash is detected.</p>
<p>&nbsp;</p>

  </TD>
</TR></TABLE>

<table width="100%" border="0"><tr><td bgcolor="#2c5d92" class="RakNetWhiteHeader">
<img src="spacer.gif" width="8" height="1">Logging</td>
</tr></table>
<TABLE BORDER="0" CELLPADDING="10" CELLSPACING="0" WIDTH="100%"><TR>
  <TD>
    <p><strong>Function call logs:</strong></p>
    <p>All function call logs to to a single table, while the parameter list to the function calls go to another table. The names of the tables are defined at the top of SQLiteServerLoggerPlugin.cpp.</p>
    <p class="RakNetCode">#define FUNCTION_CALL_TABLE 'functionCalls'<br>
      #define FUNCTION_CALL_PARAMETERS_TABLE 'functionCallParameters'</p>
    <p>All parameters are saved as strings.</p>
    <p>To log a function call, use the define rakFnLog(&quot;function name&quot;, (parameterList));</p>
    <p>For example:</p>
    <p class="RakNetCode">RakNet::SQLLogResult res;<br>
int x=1;<br>
unsigned short y=2;<br>
float c=3;<br>
double d=4;<br>
char *e=&quot;HI&quot;;<br>
res = rakFnLog(&quot;My func&quot;, (x,y,c,d,e));<br>
      RakAssert(res==RakNet::SQLLR_OK);</p>
<p>Note the parenthesis around the parameter list. This is necessary for the macro to automatically log the __FILE__ and __LINE__ files that it uses does in C++.</p>
<p>The return value is not necessary to usually check, but is good the first time you use the system. The call will fail if you did not setup the system properly.</p>
<p><strong>All other types of logs:</strong></p>
    <p>Log using the macro rakSqlLog(&quot;table name&quot;, &quot;column1,column2,column3...&quot;, (parameterList));</p>
    <p>For example:</p>
    <p class="RakNetCode">rakSqlLog(&quot;sqlLog&quot;, &quot;handle, mapName, positionX, positionY, positionZ, gameMode, connectedPlayers&quot;, (&quot;handle1&quot;, &quot;mapname1&quot;, 1,2,3,&quot;&quot;,4));<br>
  rakSqlLog(&quot;sqlLog&quot;, &quot;handle, mapName, positionX, positionY, positionZ, gameMode, connectedPlayers&quot;, (&quot;handle2&quot;, &quot;mapname2&quot;, 5,6,7,&quot;gameMode2&quot;,8));<br>
  rakSqlLog(&quot;sqlLog&quot;, &quot;x&quot;, (999));</p>
<p>The first line would create a new table in the database named &quot;sqlLog&quot;. The table would have 7 columns: <span class="RakNetCode">handle, mapName, positionX, positionY, positionZ, gameMode, connectedPlayers</span>. The types of the columns are based on the types of the parameter list - in this case, two strings, followed by 3 numbers, followed by another string, followed by another number.</p>
<p>The second line would add a row to the table created by the first line. Note - if the types in the parameter lists didn't match at this point, for example if we sent a number instead of a string for the first parameter, then the call would fail on the server.</p>
<p>The third line would add a new column 'x' to the table, of type integer, and the value 999.</p>
<p>Via macros, the values for __FILE__ and __LINE__ are also automatically sent to the server.</p>
<p><em>Tick Count</em></p>
<p>Most games update the simulation through discrete ticks. The tick count on the client is automatically sent to the server with logs. Update the tick count by calling SQLiteClientLoggerPlugin::IncrementAutoTickCount(). Ticks are supported in <a href="http://www.jenkinssoftware.com/echochamber">Echo Chamber</a> for single stepping animations.</p>
<p><em>Binary Data</em>:</p>
<p>Enclose two parameters into one value in the parameter list using the<strong> BlobDescriptor</strong> structure.</p>
<p class="RakNetCode">rakSqlLog(&quot;blobTable&quot;, &quot;blobColumn&quot;, ( &amp;RakNet::BlobDescriptor(bytes,byteLength) ));</p>
<p><em>Image Data</em>:</p>
<p>Enclose relevent parameters into one value in the parameter list using the <strong>RGBImageBlob</strong> structure.</p>
<p class="RakNetCode">RGBImageBlob(void *_data, uint16_t _imageWidth, uint16_t _imageHeight, uint16_t _linePitch, unsigned char _input_components, ImageBlobCompressionMode mode=DXT)</p>
<p>The first parameter is the data to send. The 2nd and 3rd paramters are the image dimenstions. The _linePitch parameter is the number of <em>bytes</em> per row of the _data. <span class="RakNetCode">_input_components</span> should be 3 for RGB, and 4 for RGBA. <span class="RakNetCode">mode</span>, of <span class="RakNetCode">ImageBlobCompressionMode</span>, should be the preferred encoding mode. If DXT is specified, but not supported or fails on the server, JPEG will be used instead.</p>
<p>Here's an example from SQLiteClientLoggerSample.cpp</p>
<p class="RakNetCode">rakSqlLog(&quot;gradient&quot;, &quot;gradientImage&quot;, ( &amp;RakNet::RGBImageBlob(bytes,4096,4096,4096*4,4) ));</p>
<p>&nbsp;</p></TD></TR></TABLE>


<table width="100%" border="0"><tr><td bgcolor="#2c5d92" class="RakNetWhiteHeader">
<img src="spacer.gif" width="8" height="1">See Also</td>
</tr></table>
<TABLE BORDER="0" CELLPADDING="10" CELLSPACING="0" WIDTH="100%"><TR><TD>

  <p><BR>
    <A HREF="index.html">Index</A><br>
    <a href="compilersetup.html">Compiler setup</a><br>
    <a href="lightweightdatabase.html">LightweightDatabase plugin</a><BR>
    <a href="plugininterface.html">PluginInterface</a><br>
    <a href="sqlite3plugin.html">SQLiteLogger</a><BR>
    <A HREF="http://www.jenkinssoftware.com/raknet/manual/SQLite3LoggerPluginVideo.html">SQLiteClientLoggerPlugin Video.</A>
  </p></TD></TR></TABLE>
</BODY>
</HTML>
